package 算法shiyan;
/**
 * @ProjectName: projectweb
 * @ClassName: 淘汰冠军赛
 * @Description: 请描述该类的功能
 * @Author: 1913040634刘世锦
 * @Date: 2021/5/8 15:42 .
 * @version v1.0
 */
public class 淘汰冠军赛 {
    public static void main(String[] args) {
        char[] a = new char[]{'A','B','C','D','E','F','G','H'};

        char guanjun = game(a);
        System.out.println("淘汰赛冠军最大值是:"+guanjun);
    }
    public static char game(char [ ] a){
       char max = 0;
        int i = a.length;
        while(i>1){  //经过i次循环，每次减半
            i=i/2;
            for(int j = 0;j<i;j++){
                if(compare(a[j+i],a[j]))
                    System.out.print(a[j]+"与"+a[j+i] +"比赛"+"     ");
                    a[j] = a[i+j];  //胜者存入a[j]
                System.out.println(a[j]+"胜出");
            }
           max= a[0];
        }


        return max;
    }

    private static boolean compare(int i, int i1) {
        if(i>i1)
            return true;
       else return false;

    }

}
